package com.platform.system.logic;

import com.alibaba.fastjson2.JSONArray;
import com.platform.common.constant.Constants;
import com.platform.system.domain.dto.device.AiUiConfigDto;
import com.platform.system.domain.dto.device.HumanModelManagerDto;
import com.platform.system.domain.dto.device.ModelAppInfoDto;
import com.platform.system.domain.dto.device.TenantAuthAiDto;
import com.platform.system.domain.vo.device.ModelAppInfoVo;
import com.platform.system.service.ISysAiUiConfigService;
import com.platform.system.service.ISysHumanModelManagerService;
import com.platform.system.service.ISysModelAppInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Huangkai
 */
@Slf4j
@Component
public class TenantAuthAiLogic {

    @Resource
    ISysModelAppInfoService sysModelAppInfoService;

    @Resource
    ISysHumanModelManagerService humanModelManagerService;

    @Resource
    ISysAiUiConfigService sysAiUiConfigService;

    public void buildTenantAuthAi(TenantAuthAiDto tenantAuthAiDto){
        List<ModelAppInfoDto> modelAppInfoDtoList;
        List<HumanModelManagerDto> humanModelManagerDtoList;
        List<AiUiConfigDto> aiUiConfigDtoList;
        if(!tenantAuthAiDto.getIsAll().equals(Constants.NUM_ONE)){
            //模型
            List<String> modelUidList = JSONArray.parseArray(tenantAuthAiDto.getModelUidList(), String.class);
            modelAppInfoDtoList = sysModelAppInfoService.selectModelAppInfoByUidList(modelUidList);
            //人设配置
            List<String> humanUidList = JSONArray.parseArray(tenantAuthAiDto.getHumanUidList(), String.class);
            humanModelManagerDtoList = humanModelManagerService.selectHumanModelManagerListByUidList(humanUidList);
            //aiui配置
            List<String> aiuiUidList = JSONArray.parseArray(tenantAuthAiDto.getAiuiUidList(), String.class);
            aiUiConfigDtoList = sysAiUiConfigService.selectAiUiConfigListByUidList(aiuiUidList);
        }else{
            modelAppInfoDtoList = sysModelAppInfoService.selectModelAppInfoByUidList(null);
            //人设配置
            humanModelManagerDtoList = humanModelManagerService.selectHumanModelManagerListByUidList(null);
            //aiui配置
            aiUiConfigDtoList = sysAiUiConfigService.selectAiUiConfigListByUidList(null);
        }
        if(modelAppInfoDtoList != null && modelAppInfoDtoList.size() > 0){
            tenantAuthAiDto.setModelAppInfoDtoList(modelAppInfoDtoList);
        }
        if(humanModelManagerDtoList != null && humanModelManagerDtoList.size() > 0){
            tenantAuthAiDto.setHumanModelManagerDtoList(humanModelManagerDtoList);
        }
        if(aiUiConfigDtoList != null && aiUiConfigDtoList.size() > 0){
            tenantAuthAiDto.setAiUiConfigDtoList(aiUiConfigDtoList);
        }

    }
}
